﻿@{
    ViewBag.Title = "Ins";
}
@section scripts
{   
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>  
    <script src="@Url.Content("~/Scripts/common/gridlayout.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/common/export.js")" type="text/javascript"></script>
}
<body>
   <form id="form1" runat="server" method="post" style="height: 100%">
    
<div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
                <a class="mini-button" id="refresh" iconCls="icon-search" onclick="search" plain="true">刷新</a>
                <span class="separator"></span>
                <a class="mini-button" id="check" name="check" iconCls="icon-ok" onclick="checkBill" plain="true">审核</a>
                <a class="mini-button" id="sendbill" name="sendbill" iconCls="icon-downgrade" onclick="SendExpress" plain="true">发货</a>                
                <span class="separator"></span>
                <a class="mini-button" id="export" iconCls="icon-node" onclick="setExportExcel('datagrid1')"plain="true">导出</a>
                <span class="separator"></span>
                <a class="mini-button" id="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
            </td>
        </tr>
    </table>                
</div>
           
    <div id = "DivHeader">
        <table style="margin-bottom:4px;">
            <tr>
                <td width ="70px" align="right">单据日期：</td>
                <td width ="310px">
                    @Html.Partial("~/Views/Modular/dxDateRange.cshtml") 
                </td>
                <td width ="70px" align="right">订单会员：</td>
                <td width ="190px">    
                     @Html.Partial("~/Views/Modular/LookupWeixinInfo.cshtml")                      
                </td>
                <td width ="70px" align="right">单据类型：</td>
                <td width ="100px">
                    <input id="comBillType" name ="FBillType" class="mini-combobox" style="width:100px;" 
                    showNullItem="false"  allowInput="false" align="left" data ="dBillType"/>                    
                </td>
                <td width ="70px" align="right"></td>
                <td width ="100px"></td>
            </tr>
            <tr>
                <td width ="70px" align="right">订单搜索：</td>
                <td width ="310px">
                    <input name="FBillNo" class="mini-textbox" style="width:308px;"/>
                </td>
                <td width ="70px" align="right">门店名称：</td>
                <td width ="190px">    
                    @Html.Partial("~/Views/Modular/LookupStockInfo.cshtml")  
                </td>
                <td width ="70px" align="right">审核状态：</td>
                <td width ="100px">
                    <input id="comCheckFlag" name ="FCheckFlag" class="mini-combobox" style="width:100px;" 
                    showNullItem="false"  allowInput="false" align="left" data ="dCheckFlag"/>  
                </td>
                <td width ="70px" align="right">订单状态：</td>
                <td width ="100px">
                    <input id="comBillStateID" name ="comBillStateID" class="mini-combobox" style="width:100px;" value="-1" textField="text" valueField="id"
                    showNullItem="false" allowInput="false" align="left" url="/Bill/GetBillStateKeyValueList"/>  
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit">
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:50%;" borderStyle="border:1;"pageSize="15"
            url="../Report/GetBillList"
            allowCellSelect="true" allowCellEdit="true" showSummaryRow="true" ondrawsummarycell="onDrawSummaryCell"
            fitColumns="false" onrowdblclick="editBill" sortMode="client" onselectionchanged="onSelectionChanged">
            <div property="columns">
                <div type="checkcolumn" ></div>  
                <div field="FBillName" width="80" headerAlign="center">单据类型</div>
                <div field="FBillNo" width="120" headerAlign="center">单据编号</div>    
                <div field="FDate" name="FDate" width="130px" headerAlign="center" dateFormat="yyyy-MM-dd HH:mm:ss">单据日期</div> 
                <div field="FQty" name="FQty" width="70" headerAlign="center" align="right" numberFormat="#,0.00">数量</div>
                <div field="FRealAmount" name="FRealAmount" width="90" headerAlign="center" align="right" numberFormat="#,0.00">金额</div>
                <div field="FCheckName" width="70" headerAlign="center">审核标志</div>
                <div field="FConsignee" width="80" headerAlign="center">收件人</div>
                <div field="FTelephone" width="100" headerAlign="center">联系电话</div>
                <div field="FMessage" width="150" headerAlign="center">订单留言</div>
                <div field="FStockName" width="100" headerAlign="center">门店名称</div>
                <div field="FStateName" width="100" headerAlign="center">订单状态</div>
                <div field="FDeliveryName" width="100" headerAlign="center">送货方式</div>
                <div field="FExpressNumber" width="100" headerAlign="center">物流单号</div>
                <div field="FExpressName" width="100" headerAlign="center">物流公司</div>
                <div field="FRemark" width="120" headerAlign="center">备注</div>    
                <div field="FPay" width="100" headerAlign="center">付款状态</div>
            </div>
        </div>  

        <div id="datagrid2" class="mini-datagrid" style="width:100%;height:50%;" url=""
            showPager = "false" showPageSize="false" showPageIndex="false" skipReadOnlyCell="true"
            allowCellSelect="true" allowSortColumn = "false" allowCellEdit="true"showColumnsMenu="true"  
            editNextRowCell="false" showSummaryRow="false" fitColumns="false">
            <div property="columns">            
                <div type="indexcolumn" width="35" headerAlign="center" >序号</div>
                <div field="mFNumber" name="mFNumber" displayField = "mFNumber" width="120" headerAlign="center">商品编码</div>  
                <div field="mFName" name="mFName" width="160" headerAlign="center">商品名称</div>  
                <div field="mFModel" name="mFModel" width="100" headerAlign="center">规格型号</div>
                <div field="mFUnitName" name="mFUnitName" width="40" headerAlign="center">单位</div>
                <div field="mFConvert" name="mFConvert" width="70" headerAlign="center" align="right">内装数</div>
                <div field="mFQty" name="mFQty" width="70" headerAlign="center" align="right">数量</div>
                <div field="mFPrice" name="mFPrice" width="70" numberFormat="#,0.00" headerAlign="center" align="right">单价 </div>
                <div field="mFAmount" name="mFAmount" numberFormat="#,0.00" width="90" headerAlign="center" align="right" summaryType="sum">金额</div>
                <div field="mFCode" name="mFCode" width="120" headerAlign="center">商品条码</div>                
                <div field="mFRemark" name="mFRemark" headerCls="CellLast" width="150" headerAlign="center" >备注</div>              
            </div>
        </div>     
    </div>
    
    <script type="text/javascript">

        var dBillType = [{ "id": "0", "text": "全部" },
                         { "id": "1", "text": "订单" },
                         { "id": "2", "text": "退货" }]

        var dCheckFlag = [{ "id": "0", "text": "全部" },
                         { "id": "1", "text": "未审核" },
                         { "id": "2", "text": "已审核" }]

        mini.parse();
        var form = new mini.Form("form1");
        var grid = mini.get("datagrid1");
        var grid2 = mini.get("datagrid2");
        var uID = parent.window.getSystemAppID();
        var hdatatype = getQueryString("datatype");
        var checkFlag = getQueryString("CheckFlag");
        var sumFields = "FQty,FRealAmount";

        function FormShown() {
            var toDay = new Date();
            mini.getbyName("FDate1").setValue(toDay);
            mini.getbyName("FDate2").setValue(toDay);
            mini.getbyName("FCheckFlag").select(0);
            mini.getbyName("FBillType").select(0);
        }

        $(function () {
            if (checkFlag != null) {
                mini.getbyName('FCheckFlag').select(checkFlag);
                mini.getbyName('comdatasel').select(6);
                onComDataselChanged();
            }
            else {
                var nowDate = new Date();
                mini.getbyName("FDate1").setValue(nowDate);
                mini.getbyName("FDate2").setValue(nowDate);
            }
            search();
        });

        function editBill() {
            var row = grid.getSelected();
            if (row) {
                var mDataType = row.FDataType;
                if (mDataType == 5) {
                    parent.window.showTabByIdEx('77','MallData', '订单管理', '../Bill/MallData?datatype=5&billid=' + row.KInterID);
                }
            }
        }

        function removeBill() {
            var row = grid.getSelected();
            if (row) {
                var mCheckFlag = row.FCheckFlag;
                if (!mCheckFlag) {
                    mini.confirm("确定要删除该单据吗？", "提示",
                        function (action) {
                            if (action == "ok") {
                                SetRemoveBill(row);
                            }
                        }
                   );
                }
                else {
                    mini.alert("已审核的单据不能删除!");
                }
            }
        }

        function SetRemoveBill(row) {
            var json = "[{";
            json = json + "'KInterID':'" + row.KInterID + "',";
            json = json + "'FDataType':'" + row.FDataType + "',";
            json = json + "'FSystemAppID':'" + uID + "'}]";
            $.ajax({
                url: '../Bill/RemoveBillData',
                data: { mdatajson: json },
                type: "post",
                cache: false,
                success: function (txt) {
                    var ret = mini.decode(txt);
                    if (ret.id != -1) {
                        grid.removeRow(row, true);
                        mini.showMessageBox({
                            showModal: false, width: 250, title: "提示", iconCls: "mini-messagebox-info",
                            message: ret.Status, timeout: 3000, x: "right", y: "bottom"
                        });
                    }
                    else {
                        mini.alert("异常:" + ret.Status);
                    }
                },
                error: function (xhr) {
                    mini.alert("异常:" + xhr.responseText);
                }
            });
        }

        function search() {
            var cDate1 = mini.getbyName("FDate1").getFormValue();
            var cDate2 = mini.getbyName("FDate2").getFormValue();
            var mCheckFlag = mini.getbyName("FCheckFlag").getValue();
            var mBillType = mini.getbyName("FBillType").getValue();
            var mBillNo = mini.getbyName("FBillNo").getValue();
            var mStockID = mini.getbyName("FStockID").getValue();
            var mWeixinID = mini.getbyName("FWeixinID").getValue();
            var mBillStateID = mini.getbyName("comBillStateID").getValue();

            var json = "[{";
            json = json + '"mListType":' + '"' + hdatatype + '",';//列表类型
            json = json + '"mSystemAppID":' + '"' + uID + '",';
            json = json + '"mDate1":' + '"' + cDate1 + '",';
            json = json + '"mDate2":' + '"' + cDate2 + '",';
            json = json + '"mCheckFlag":' + '"' + mCheckFlag + '",';
            json = json + '"mBillType":' + '"' + mBillType + '",';
            json = json + '"mStockID":' + '"' + mStockID + '",';
            json = json + '"mObjectID":' + '"' + mWeixinID + '",';
            json = json + '"mBillStateID":' + '"' + mBillStateID + '",';
            json = json + '"mBillNo":' + '"' + mBillNo + '"';
            json = json + "}]";

            grid.load({ mydata: json });

            mExportDataUrl = grid.url;
            mExportDataJson = json;//导出
        }

        function checkBill() {
            var row = grid.getSelected();
            if (row) {
                var mCheckFlag = row.FCheckFlag;
                if (mCheckFlag) {
                    mini.alert("已单已审核!");
                }
                else {
                    mini.confirm("确定要审核该单据吗？", "提示",
                        function (action) {
                            if (action == "ok") {
                                setcheckBill(row);
                            }
                        }
                   );
                }
            }
        }

        function setcheckBill(row) {
            var kid = row.KInterID;
            var json = "[{";
            json = json + "'KInterID':'" + kid + "',";
            json = json + "'FDataType':'5',";
            json = json + "'FSystemAppID':'" + uID + "'}]";
            $.ajax({
                url: '../Bill/CheckBillData',
                data: { mdatajson: json },
                type: "post",
                cache: false,
                success: function (txt) {
                    var ret = mini.decode(txt);
                    mini.showMessageBox({
                        showModal: false, width: 250, title: "提示", iconCls: "mini-messagebox-info",
                        message: ret.Status, timeout: 3000, x: "right", y: "bottom"
                    });

                    if (ret.id != -1) {
                        search();
                    }
                    else {
                        mini.alert("异常:" + ret.Status);
                    }
                },
                error: function (xhr) {
                    mini.alert("异常:" + xhr.responseText);
                }
            });
        }

        function onSelectionChanged(e) {
            var mgrid = e.sender;
            var record = mgrid.getSelected();
            if (record) {
                var mKInterID = record.KInterID;
                GetBillDetail(mKInterID);
                var mCheckFlag = record.FCheckFlag;
                if (mCheckFlag) {
                    mini.get("sendbill").setEnabled(true);
                    mini.get("check").setEnabled(false);
                }
                else {
                    mini.get("sendbill").setEnabled(false);
                    mini.get("check").setEnabled(true);
                }
            }
        }

        function GetBillDetail(minterid) {
            $.ajax({
                url: '../Bill/GetBillData',
                data: { mSystemAppID: uID, mBillID: minterid, mDataType: 5 },
                dataType: 'text',
                async: false,
                success: function (text) {
                    var dataR = mini.decode(text);
                    grid2.setData(dataR.datadetail);
                }
            });
        }

        function printdata() {
            var url = "../Report/PrintReport";
            mini.open({
                url: url,
                title: "打印", width: 1000, height: 700,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var NoneDisplayCol = [0];
                    var headtext = "";
                    headtext = "电商订单列表";
                    iframe.contentWindow.InitalPrint(grid, NoneDisplayCol, parent.window.getSystemCompany() + headtext);
                }
            });
        }

        function SendExpress() {
            var mgrid = mini.get("datagrid1");
            var record = mgrid.getSelected();
            if (record) {
                mini.open({
                    url: "../Mall/SendExpress",
                    title: "订单发货", width: 500, height: 300,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        headtext = "电商订单发货";
                        iframe.contentWindow.setData(record.KInterID);
                    },
                    ondestroy: function (action) {
                        mgrid.reload();
                    }
                });
            }
        }
    </script>

    </form>
</body>